#include "DeviceInfo.h"
#include <string.h>

static DeviceInfo stDeviceInfo;
static SystemRunTimeInfo stSystemRunTimeinfo;

DeviceInfo *GetDeviceInfo(void)
{
	return &stDeviceInfo;
}

SystemRunTimeInfo *GetSysRunTimeInfo(void)
{
	return &stSystemRunTimeinfo;
}

bool isDeviceConnectServerOK(void)
{
	return stSystemRunTimeinfo.bDeviceConnectServerOK;
}

bool canDeviceLoginOK(void)
{
	return stSystemRunTimeinfo.bDeviceLoginOK;
}

bool canDeviceWork(void)
{
	return stSystemRunTimeinfo.bDeviceCanWork;
}

void setDeviceConnectServerOK(bool bDeviceConnectServerOK)
{
	stSystemRunTimeinfo.bDeviceConnectServerOK = bDeviceConnectServerOK;
}

void setDeviceLoginOK(bool bDeviceLoginOK)
{
	stSystemRunTimeinfo.bDeviceLoginOK = bDeviceLoginOK;
}


//与服务段通信用的标识符ID
//后续考虑这个ID是否需要存到DeviceInfo中
//最终放到Flash中保存
uint32_t getComServID(void)
{
	return stSystemRunTimeinfo.u32ComSvrID;
}

void setComServID(uint32_t svrID)
{
	stSystemRunTimeinfo.u32ComSvrID = svrID;
}

//电池包容量
uint16_t getPackCapcity(void)
{
	return stSystemRunTimeinfo.u16PackCapcity;
}

void setPackCapcity(uint16_t cap)
{
	stSystemRunTimeinfo.u16PackCapcity = cap;
}


//电池包电池串数
uint8_t getPackSerialCount(void)
{
	return stSystemRunTimeinfo.u8PackSerialCount;
}

void setPackSerialCount(uint8_t serCnt)
{
	stSystemRunTimeinfo.u8PackSerialCount = serCnt;
}

//设备MCUID
void getDevMCUID(uint8_t* mcuID)
{
	memcpy(mcuID, &(stSystemRunTimeinfo.u8DevMCUID),
		sizeof(stSystemRunTimeinfo.u8DevMCUID));
}

void setDevMCUID(uint8_t* mcuID)
{
	memcpy(&(stSystemRunTimeinfo.u8DevMCUID), mcuID,
		sizeof(stSystemRunTimeinfo.u8DevMCUID));
}

//设置设备是否允许工作
void setDeviceWork(bool canWork)
{
	stSystemRunTimeinfo.bDeviceCanWork = canWork;
}

//设备是否需要升级
bool getDevNeedUpdate(void)
{
	return stSystemRunTimeinfo.bDevNeedUpdate;
}	

void setDevNeedUpdate(bool needUpdate)
{
	stSystemRunTimeinfo.bDevNeedUpdate = needUpdate;
}

void Get_Can_Addr(uint16_t *addr)
{
	uint16_t tmp_addr = 0xA55A;
	*addr = (tmp_addr & 0x07);
}

uint8_t GetMCUID(uint8_t* idReadBuf)
{
	uint32_t chipID[3] = {0};
	uint8_t i = 0;
	chipID[0] = *(uint32_t*)(0x1FFF7A10);
	chipID[1] = *(uint32_t*)(0x1FFF7A14);
	chipID[2] = *(uint32_t*)(0x1FFF7A18);
	
	idReadBuf[0] = chipID[0]>>24;
	idReadBuf[1] = chipID[0]>>16;
	idReadBuf[2] = chipID[0]>>8;
	idReadBuf[3] = chipID[0]&0xFF;
	idReadBuf[4] = chipID[1]>>24;
	idReadBuf[5] = chipID[1]>>16;
	idReadBuf[6] = chipID[1]>>8;
	idReadBuf[7] = chipID[1]&0xFF;
	idReadBuf[8] = chipID[2]>>24;
	idReadBuf[9] = chipID[2]>>16;
	idReadBuf[10] = chipID[2]>>8;
	idReadBuf[11] = chipID[2]&0xFF;

	return 0;
	
}





